package com.sf.fy.uav.common.utils;

/**
 * @author 01430312
 * @author yangfei
 */
public class MobileNumberValidatorUtil {
    public static boolean isValidChineseMobileNumber(String number) {
        // 正则表达式验证中国大陆手机号
        String regex = "^1[3-9]\\d{9}$";
        return number.matches(regex);
    }

    public static void checkPhone(String phone) {
        if (!isValidChineseMobileNumber(phone) && !isValidChinesePhoneNumber(phone)) {
            throw new RuntimeException("手机号码或电话号码格式错误！");
        }
    }

    public static boolean isValidChinesePhoneNumber(String phoneNumber) {
        String regex = "(\\d{3,4})?\\d{7,8}(-\\d{1,4})?";
        return phoneNumber.matches(regex);
    }


    public static boolean isValidChinesePhoneNumberWithNoExtensionNumber(String phoneNumber) {
        String regex = "(\\d{3,4})?\\d{7,8}?";
        return phoneNumber.matches(regex);
    }

    public static boolean isValidExtensionNumber(String phoneNumber) {
        String regex = "(\\d{1,4})?";
        return phoneNumber.matches(regex);
    }

    public static void main(String[] args) {
        boolean isValid = isValidChinesePhoneNumberWithNoExtensionNumber("88888888");
        boolean isValidCode = isValidExtensionNumber("8888");
        System.out.println(isValid);
        System.out.println(isValidCode);
//        String[] testNumbers = {"021-88888888", "021888888888", "000-88888888-8888", "12345678901"};
//        for (String number : testNumbers) {
//            boolean isValid = isValidChinesePhoneNumberWithNoExtensionNumber(number);
//            System.out.println(number + " is valid: " + isValid);
//        }
    }
}